async function fn() {
    const res = await axios({
      url: "/dashboard",
      method: "get",
    });
    console.log(res);
    for (const key in res.data.data.overview) {
        // console.log(document.querySelector(`[name=${key}]`));
        document.querySelector(`[name=${key}]`).innerHTML=res.data.data.overview[key]
    }


  function salary(year){
      // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.querySelector("#line"));
      console.log(myChart);
      // 指定图表的配置项和数据
      var option = {
        title: {
          text: "2021全学科薪资走势",
          top:'5%',
          left:'4%'
        },
        tooltip: {
          show: true,
          trigger: "axis",
        },
        grid: {
          left: "10%",
          top: "29%",
        },
        legend: {
          data: ["热度"],
          bottom: "0%",
        },
        xAxis: {
          type: "category",
          data: year.map(v=>v.month),
          axisLine: {
            show: true,
            lineStyle: {
              color: "rgba(0, 0, 0, 1)",
              type: "dashed",
            },
          },
        },
  
        yAxis: {
          type: "value",
          splitLine: {
            lineStyle: {
              type: "dashed",
            },
          },
        },
        series: [
          {
            data: year.map(v=>v.salary),
            type: "line",
            smooth: true,
            symbol: "emptyCircle",
            symbolSize: 10,
            lineStyle: {
              width: 6,
              color: "#608bff",
            },
            // 渐变阴影
            areaStyle: {
              color: {
                type: "linear",
                x: 0,
                y: 0,
                x2: 0,
                y2: 1,
                colorStops: [
                  {
                    offset: 0,
                    color: "rgba(83,168,255,1)", // 0% 处的颜色
                  },
                  {
                    offset: 0.8,
                    color: "rgba(89,154,255,0)", // 100% 处的颜色
                  },
                ],
                global: false, // 缺省为 false
              },
            },
          },
        ],
      };
      // 使用刚指定的配置项和数据显示图表。
      option && myChart.setOption(option);
    }
      salary(res.data.data.year)
      // salary()


      function pie(salary){
        const data=salary.map(v=>{
          return   { 
          value:v.b_count+v.g_count,name:v.label
        }
          })
          // 基于准备好的dom，初始化echarts实例
      var myChart = echarts.init(document.querySelector("#salary"));

      // 指定图表的配置项和数据

      option = {
        title: {
          text: "班级薪资分布",
          top:'5%',
          left:'5%',
          textStyle: {
            fontSize: 20,
          },
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          bottom: "0%",
          left: "center",
        },
        series: [
          {
            name: "Access From",
            type: "pie",
            radius: ["70%", "85%"],
            avoidLabelOverlap: false,
            lineStyle: {
              width: 20,
            },
            itemStyle: {
              borderRadius: 10,
              borderColor: "#fff",
              borderWidth: 5,
            },
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: true,
                fontSize: "40",
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
           
            data
          },
        ],
        color: ["#fac03d", "#597eed", "#42bafb", "#3ed3a8"],
      };

      // 使用刚指定的配置项和数据显示图表。
      myChart.setOption(option);
      }
      pie(res.data.data.salaryData)

      function groupData(group){
        console.log(group);

        console.log(group[1]);
        var chartDom = document.getElementById("lines");
        var myChart = echarts.init(chartDom);
        var option;
    
        option = {
          // title: {
          //   text: "班级每组薪资",
          // },
          
            tooltip: {
              show: true,
              trigger: "item"
            }
          ,
          color: [
            {
              type: "linear",
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [
                {
                  offset: 0,
                  color: "rgba(81, 217, 168,1)", // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: "rgba(81, 217, 168,0)", // 100% 处的颜色
                },
              ],
              global: false, // 缺省为 false
            },
            {
              type: "linear",
              x: 0,
              y: 0,
              x2: 0,
              y2: 1,
              colorStops: [
                {
                  offset: 0,
                  color: "rgba(73, 159, 238,1)", // 0% 处的颜色
                },
                {
                  offset: 1,
                  color: "rgba(73, 159, 238,0)", // 100% 处的颜色
                },
              ],
              global: false, // 缺省为 false
            },
          ],
          xAxis: {
            type: "category",
            data: group[1].map(v=>v.name),
            axisLine: {
              show: true,
              lineStyle: {
                type: "dashed",
              },
            },
          },
          yAxis: {
            type: "value",
          },
          series: [
            {
              name:'期望工资',
              data:group[1].map(v=>v.hope_salary),
              type: "bar",
            },
            {
              name:'实际工资',
              data:group[1].map(v=>v.salary),
              type: "bar",
            },
          ],
        };
    
        option && myChart.setOption(option);

        // 切换高亮
        const btns=document.querySelectorAll('#btns button')
        btns.forEach(v=>{
          v.onclick=function(){
            document.querySelector('.btn-blue').classList.remove('btn-blue')
            this.classList.add('btn-blue')
            const num = this.innerHTML
            option.xAxis.data=group[num].map(v=>v.name)
            option.series[0].data=group[num].map(v=>v.hope_salary)
            option.series[1].data=group[num].map(v=>v.salary)
            myChart.setOption(option)
          }
        })
        console.log(btns);
      }

      groupData(res.data.data.groupData)

      function  genderBar(salaryData){
        var chartDom = document.getElementById("gender");
        var myChart = echarts.init(chartDom);
        var option;
    
        option = {
          title: [
            {
              text: "男女薪资分布",
              left: "3%",
              top: "4%",
            },
            {
              text: "男生",
              left: "center",
              top: "45%",
            },
            {
              text: "女生",
              left: "center",
              top: "90%",
            },
          ],
          tooltip: {
            trigger: "item",
          },
          legend: {
            show: false,
            orient: "vertical",
            left: "left",
          },
          grid: {
            show: false,
            left: "100%",
          },
          color: ["#fac03d", "#597eed", "#42bafb", "#3ed3a8"],
    
          series: [
            // 男生
            {
              name: "Access From",
              type: "pie",
              radius: ["20%", "30%"],
              center: ["50%", "25%"],
              itemStyle: {
                borderColor: "#fff",
              },
              data: salaryData.map(v=>{
                return {
                  value:v.b_count,
                  name:v.label
                }
              }),
    
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: "rgba(0, 0, 0, 0.5)",
                },
              },
            },
            // 女生
            {
              name: "Access From",
              type: "pie",
              radius: ["20%", "30%"],
              center: ["50%", "70%"],
              itemStyle: {
                borderColor: "#fff",
              },
              data: 
                  salaryData.map(v=>{
                    return {
                      value:v.g_count,
                      name:v.label
                    }
                  })
                // { value: 1048, name: "Search Engine" },
                // { value: 735, name: "Direct" },
                // { value: 580, name: "Email" },
                // { value: 484, name: "Union Ads" },
                // { value: 300, name: "Video Ads" },
              ,
    
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: "rgba(0, 0, 0, 0.5)",
                },
              },
            },
          ],
        };
        option && myChart.setOption(option);
      }

      genderBar(res.data.data.salaryData)

      function initMapChart(provinceData){
          const myEchart = echarts.init(document.querySelector('#map'))
          const dataList = [
            { name: '南海诸岛', value: 0 },
            { name: '北京', value: 0 },
            { name: '天津', value: 0 },
            { name: '上海', value: 0 },
            { name: '重庆', value: 0 },
            { name: '河北', value: 0 },
            { name: '河南', value: 0 },
            { name: '云南', value: 0 },
            { name: '辽宁', value: 0 },
            { name: '黑龙江', value: 0 },
            { name: '湖南', value: 0 },
            { name: '安徽', value: 0 },
            { name: '山东', value: 0 },
            { name: '新疆', value: 0 },
            { name: '江苏', value: 0 },
            { name: '浙江', value: 0 },
            { name: '江西', value: 0 },
            { name: '湖北', value: 0 },
            { name: '广西', value: 0 },
            { name: '甘肃', value: 0 },
            { name: '山西', value: 0 },
            { name: '内蒙古', value: 0 },
            { name: '陕西', value: 0 },
            { name: '吉林', value: 0 },
            { name: '福建', value: 0 },
            { name: '贵州', value: 0 },
            { name: '广东', value: 0 },
            { name: '青海', value: 0 },
            { name: '西藏', value: 0 },
            { name: '四川', value: 0 },
            { name: '宁夏', value: 0 },
            { name: '海南', value: 0 },
            { name: '台湾', value: 0 },
            { name: '香港', value: 0 },
            { name: '澳门', value: 0 },
          ]
        //  把后端数据的value 给 dataList的value
        provinceData.forEach(v=>{
          dataList.forEach(item=>{
            // console.log(v.name.indexOf(item.name));
          //  a.indexof(b) 如果在 a 中能找到 b ,返回相对应的索引号,找不到返回-1
            if (v.name.indexOf(item.name)!== -1) {
              item.value = v.value
            }
          })
        })
          let option = {
            title: {
              text: '籍贯分布',
              top: 10,
              left: 10,
              textStyle: {
                fontSize: 16,
              },
            },
            tooltip: {
              trigger: 'item',
              formatter: '{b}: {c} 位学员',
              borderColor: 'transparent',
              backgroundColor: 'rgba(0,0,0,0.5)',
              textStyle: {
                color: '#fff',
              },
            },
            visualMap: {
              min: 0,
              max: 6,
              left: 'left',
              bottom: '20',
              text: ['6', '0'],
              inRange: {
                color: ['#ffffff', '#0075F0'],
              },
              show: true,
              left: 40,
            },
            geo: {
              map: 'china',
              roam: false,
              zoom: 1.0,
              label: {
                normal: {
                  show: true,
                  fontSize: '10',
                  color: 'rgba(0,0,0,0.7)',
                },
              },
              itemStyle: {
                normal: {
                  borderColor: 'rgba(0, 0, 0, 0.2)',
                  color: '#e0ffff',
                },
                emphasis: {
                  areaColor: '#34D39A',
                  shadowOffsetX: 0,
                  shadowOffsetY: 0,
                  shadowBlur: 20,
                  borderWidth: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)',
                },
              },
            },
            series: [
              {
                name: '籍贯分布',
                type: 'map',
                geoIndex: 0,
                data: dataList,
              },
            ],
          }
          myEchart.setOption(option)
        }
        initMapChart(res.data.data.provinceData)
      }
      
    
  
   
    
  
  fn();